import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { IotProductVO, IotProductQuery, IotProductForm } from './types'

/**
 * 查询产品列表
 * @param query
 */
export const listProduct = (query?: IotProductQuery): AxiosPromise<IotProductVO[]> => {
  return request({
    url: '/iot/product/list',
    method: 'get',
    params: query
  })
}

/**
 * 分页查询产品列表
 * @param query
 */
export const pageProduct = (query: IotProductQuery): AxiosPromise<any> => {
  return request({
    url: '/iot/product/page',
    method: 'get',
    params: query
  })
}

/**
 * 查询产品详细
 * @param productId
 */
export const getProduct = (productId: string | number): AxiosPromise<IotProductVO> => {
  return request({
    url: '/iot/product/' + productId,
    method: 'get'
  })
}

/**
 * 新增产品
 * @param data
 */
export const addProduct = (data: IotProductForm) => {
  return request({
    url: '/iot/product',
    method: 'post',
    data: data
  })
}

/**
 * 修改产品
 * @param data
 */
export const updateProduct = (data: IotProductForm) => {
  return request({
    url: '/iot/product',
    method: 'put',
    data: data
  })
}

/**
 * 删除产品
 * @param productIds
 */
export const delProduct = (productIds: string | number | Array<string | number>) => {
  return request({
    url: '/iot/product/' + productIds,
    method: 'delete'
  })
}